package ch8recursion;

public class Ex6 {
	enum Color {
		Black, White, Red, Yellow, Green
	}

	void paintFill(Color[][] screen, int x, int y, Color ocolor, Color ncolor) {
		if (x < 0 || x >=screen.length || y < 0 || y >= screen.length) {
			return;
		}
		
		if (screen[x][y] == ocolor) {
			screen[x][y] = ncolor;
			paintFill(screen, x-1, y, ocolor, ncolor);
			paintFill(screen, x+1, y, ocolor, ncolor);
			paintFill(screen, x, y-1, ocolor, ncolor);
			paintFill(screen, x, y+1, ocolor, ncolor);			
		}
		return;
	}

	void PaintFill(Color[][] screen, int x, int y, Color ncolor) {
		paintFill(screen, x, y, screen[y][x], ncolor);
	}
}
